/**
  ******************************************************************************
  * @file           : mcu_application.h
  * @brief          : Header for mcu_application.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *	Created by Chen Lu in 20210612
  *
  ******************************************************************************
  * Maybe nobody will read the code and comments in the project. I still comment
  * on nearly every problem I've come across for responsibilities, notwithstanding
  * really a mess the code is.
  ******************************************************************************
  */

#ifndef __MCU_APPLICATION_H
#define __MCU_APPLICATION_H

#include "main.h"
#include "sio_service.h"
#include "motion_service.h"
#include "queue.h"
#include "mcu_application.h"

#define MCUAPPLICATION_OK		1
#define MCUAPPLICATION_ERROR	0

//FSM states
#define CLOSE	0
#define OPEN	1
#define IDLE	2
#define RUNNING	3
#define STOP	4

typedef struct {
	uint8_t state;
	uint8_t request[127];
	uint16_t request_length;
	uint8_t response[127];
	/** Here use structure instead of pointer. If using pointer, the "last" pointer in the queue when initiating turns
	 *  to be Reset_Handler, which leads to a HardFault_Handler.
	 */
	Queue task_seq;
	TiMotionService * mcs;
	TiSioService * sio;
}TiMcuApplication;

TiMcuApplication *mcu_app_open(void);
uint8_t mcu_app_run(TiMcuApplication* mcu_app);
uint8_t excute_task(TiMcuApplication* mcu_app, TiTask task, float* angle);
uint8_t mcu_app_close(TiMcuApplication* mcu_app);

#endif /* __MCU_APPLICATION_H */
